<?php
class HtmlDB
{
	// Mysql Data Management
	function connect($host,$user,$pass,$db){
		mysql_connect($host,$user,$pass) or $this->_mysql_error();
		mysql_select_db($db) or $this->_mysql_error();
	}
	function query($q,$a=array()){
	  mysql_query("SET NAMES 'utf8'") or die(mysql_error());
	  $sql = $this->_escape_all($q,$a);
	  $res = mysql_query($sql);
	  $res or $this->_mysql_error();
	  return $res;
	}
	//Private Function
	function _mysql_error($s=''){
	  die($s.'<br /><font color="red">'.htmlspecialchars(mysql_error()).'</font>');
	}
	function _escape_all(&$q,&$a){
		 $query = '';
		 $s = explode('?',$q);
		 $maxdec1 = count($s)-1;
		 for($i=0;$i < $maxdec1; $i++){
		   $query .= $s[$i].mysql_real_escape_string($a[$i]);
		 } $query .= $s[$i];
		 return $query;
	}
}
?>